<?php
namespace frontend\controllers;

use frontend\models\ContactForm;
use Yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\helpers\Url;
use yii\web\Controller;
use yii\web\Response;
use yii\base\ErrorException;
use yii\helpers\Html;
use common\widgets\file_upload\FileUpload;
use common\models\member\Member;
use common\models\category\Category;
use common\models\articles\Articles;
use common\models\art\Art;
use common\models\meeting\Meeting;
use yii\data\Pagination;
use yii\web\Request;

class VideoController extends Controller
{     
	public $layout = 'nomalpage';	
	public function actions()
    {
        return [
            'upload'=>[
                'class' => 'common\widgets\file_upload\UploadAction',     //这里扩展地址别写错
                'config' => [
                ]
            ],
			'ueditor'=>[
				'class' => 'common\widgets\ueditor\UeditorAction',
				'config'=>[
					//上传图片配置
					'imageUrlPrefix' => "", /* 图片访问路径前缀 */
					'imagePathFormat' => "/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
				]
			]
        ];
    }

    /**
    * 新闻列表 zsn 20161229
    */
  public function actionIndex($id){

    /*    $tid     父栏目id
          $id      当前栏目id
    */
      // 是否跳转到子栏目
	 	if(Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['parent_id'] == 0){
	 		$tid = $id;
	 		$childcat = Category::find()->where(['status'=> 1, 'parent_id'=> $id])->asArray()->all();
	 		$id = $childcat[0]['id'];
			$parenttitle = Category::find()->where(['status'=> 1, 'id'=> $tid])->asArray()->one()['name'];
      $parentinfo = Category::find()->where(['status'=> 1, 'id'=> $tid])->asArray()->one();
	 	}else{
	 		$parentid = Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['parent_id'];
	 		$childcat = Category::find()->where(['status'=> 1, 'parent_id'=> $parentid])->asArray()->all();
	 		$tid = $parentid;
      $parenttitle = Category::find()->where(['status'=> 1, 'id'=> $parentid])->asArray()->one()['name'];
			$parentinfo = Category::find()->where(['status'=> 1, 'id'=> $parentid])->asArray()->one();
	 	}

    // 判断导航状态
	 	$view = Yii::$app->view;
	 	$view->params['tid'] = $tid; 

	 	$title = Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['name'];
	 	$ctype = Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['ctype'];

    
	 	$query = Articles::find()->where(['category_id'=>$id, 'status' => Articles::STATUS_ACTIVE]);
		$count = $query->count();
		$page = new Pagination(['totalCount' => $count, 'pageSize' => '24']);
		$articles = $query->offset($page->offset)
		    ->limit($page->limit)
		    ->all();
        $view = Yii::$app->view;  
        $view->params['tid']=$tid;
        return $this->render('index',[
          'tid' => $tid,
          'id' => $id,
      	  'title' => $title,
          'parenttitle'=>$parenttitle,
		      'parentinfo'=>$parentinfo,
      	  'ctype' => $ctype,
          'childcat' => $childcat,
          'articles' => $articles,
          'page' => $page,
        ]);
  }
}